from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5 import QtGui

import sys

class QInputDialogTest(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(QInputDialogTest, self).__init__(parent)

        self.setWindowTitle("QInputDialogTest例子")

        self.btn1 = QtWidgets.QPushButton(self)
        self.btn1.setText("获取列表里的选项")
        self.btn1.clicked.connect(self.get_item)
        self.le_item_selected = QtWidgets.QLineEdit()

        self.btn2 = QtWidgets.QPushButton(self)
        self.btn2.setText("获取字符串")
        self.btn2.clicked.connect(self.get_string)
        self.le_string_input = QtWidgets.QLineEdit()

        self.btn3 = QtWidgets.QPushButton(self)
        self.btn3.setText("获取整数")
        self.btn3.clicked.connect(self.get_int)
        self.le_int_input = QtWidgets.QLineEdit()

        _layout = QtWidgets.QFormLayout()
        _layout.addRow(self.btn1, self.le_item_selected)
        _layout.addRow(self.btn2, self.le_string_input)
        _layout.addRow(self.btn3, self.le_int_input)
        self.setLayout(_layout)

    def get_item(self):
        _items = ["c", "c++", "java", "python"]
        item, ok = QtWidgets.QInputDialog.getItem(self, "select input dialog", "语言列表", _items, 0, False)
        if ok and item:
            self.le_item_selected.setText(item)

    def get_string(self):
        text, ok = QtWidgets.QInputDialog.getText(self, "Text Input Dialog", "输入姓名：")
        if ok:
            self.le_string_input.setText(text)

    def get_int(self):
        num, ok = QtWidgets.QInputDialog.getInt(self, "Int Input Dialog", "输入数字")
        if ok:
            self.le_int_input.setText(str(num))


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    QtWidgets.QApplication.setStyle("Fusion")
    win = QInputDialogTest()
    win.show()
    sys.exit(app.exec_())